﻿using System;
using System.Security.Cryptography;
using System.Web.Security;

namespace DevTeam
{
    public static class CryptoManager
    { 
        public static string GetObjectHash(Type type, object[] prm)
        {
            string prmHash = "";
            foreach (object o in prm)
                prmHash += o.GetHashCode();

            return type.GetHashCode() + "." + prmHash;
        }

        public static string[] GetSaltedHash(string password)
        {
            int SaltByteSize = 10;    //16 idi!

            RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
            byte[] buff = new byte[SaltByteSize];
            rng.GetBytes(buff);
            string salt = Convert.ToBase64String(buff).Substring(0, 10);
            return new string[] { salt, FormsAuthentication.HashPasswordForStoringInConfigFile(salt + password, "SHA1") };
        }
    }
}